package com.mxpio.erp.quality.service.impl;

import com.mxpio.erp.common.quality.entity.InspectionBillCheckDetail;
import com.mxpio.erp.common.quality.entity.InspectionBillSimple;
import com.mxpio.erp.common.quality.service.InspectionBillSimpleService;
import com.mxpioframework.jpa.JpaUtil;
import com.mxpioframework.system.service.impl.BaseServiceImpl;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
public class InspectionBillSimpleServiceImpl extends BaseServiceImpl<InspectionBillSimple> implements InspectionBillSimpleService {
    @Override
    @Transactional
    public int deleteByBizNo(String bizNo) {
        return JpaUtil.lind(InspectionBillSimple.class).equal("bizNo", bizNo).delete();
    }

    @Override
    @Transactional
    public void computeCheckedDetects(String bizNo,List<InspectionBillSimple> inspectionBillSimples) {
        if (CollectionUtils.isNotEmpty(inspectionBillSimples)){
            for (InspectionBillSimple simple:inspectionBillSimples){
                List<InspectionBillCheckDetail> list = JpaUtil.linq(InspectionBillCheckDetail.class).equal("bizNo", bizNo).equal("simpleCode", simple.getSimpleCode()).isNotNull("testResult").list();
                simple.setCheckDetectNum(list.size());
            }
        }
    }
}
